package com.marchsoft.controller;

import com.marchsoft.common.advice.CommonExceptionHandler;
import com.marchsoft.domain.Student;
import com.marchsoft.service.IStudentService;
import com.marchsoft.vo.StuAndHistoryTea;
import com.marchsoft.vo.StudentExtra;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


/**
 * 学生表的控制类
 *
 * @author rsw
 */
@RestController
@RequestMapping("student")
public class StudentController extends CommonExceptionHandler {

    @Autowired
    private IStudentService studentService;

    /**
     * 查询学生信息（附带专业导师信息、附带所属兴趣小组的信息、附带兴趣小组的老师信息）
     *
     * 可能会用到转发，将学生的id转发过来
     * @param sid 学生id
     * @return 学生信息（附带专业导师信息、附带所属兴趣小组的信息、附带兴趣小组的老师信息）
     */
    @RequestMapping("/info")
    public ResponseEntity<StudentExtra> queryStudentInfoWithTeacher(@RequestParam("sid") Integer sid) {

        return ResponseEntity.ok(studentService.queryStudentInfoWithTeacher(sid));
    }

    /**
     * 学生退组
     * @param sid 学生id
     * @param gid 小组id
     * @return 返回true&false
     */
    @RequestMapping("exit/group")
    public ResponseEntity<Boolean> deleteGroupWithStudentBySid(Integer sid, Integer gid) {
        return ResponseEntity.ok(studentService.updateGroupWithStudentBySid(sid, gid));
    }

    /**
     * 查询学生信息和历史导师、历史兴趣小组信息
     * @param sid 学生id
     * @return 学生信息和历史导师、历史兴趣小组信息
     */
    @RequestMapping("query/student-history")
    public ResponseEntity<Map<String,Object>> queryTeacherBySidWithStatus(Integer sid){
        return ResponseEntity.ok(studentService.studentWithHistoryInfo(sid));
    }

    /**
     * 查询导师的学生
     *
     * @param tid 导师id
     * @return
     */
    @RequestMapping("/TeaStudent")
    public ResponseEntity<List<Student>> queryMystudentByteacher(Integer tid) {
        List<Student> list = null;
        list = studentService.queryMystudentByteacher(tid);
        return ResponseEntity.ok(list);
    }

    /**
     * 查询小组的学生
     *
     * @param gid 小组id
     * @return
     */
    @RequestMapping("/GroStudent")
    public ResponseEntity<List<Student>> queryMystudentByGroup(Integer gid) {
        List<Student> list = null;
        list = studentService.queryMystudentByGroup(gid);
        return ResponseEntity.ok(list);
    }

    /**
     * 查询该学生信息和其历史导师
     * @param sid
     * @return
     */
    @RequestMapping("/queryStuAndHistoryTea")
    public ResponseEntity<StuAndHistoryTea> queryStuAndHistoryTea(
            @RequestParam(name = "sid",required = true) Integer sid){
        return ResponseEntity.ok(studentService.queryStuAndHistoryTea(sid));
    }

}
